# python爬取读书网数据案例
# import requests
# from bs4 import BeautifulSoup
# import time
# import math
# import json
#
# domain = "https://www.dushu.com"
# url = "https://www.dushu.com/book/1181.html"
# url2 = "https://www.dushu.com/book/1181"
#
# headers = {
#     "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36'
# }
#
# my_book_list = []
#
# t1 = time.time()
# # 爬取10页数据
# for i in range(1, 10):
#     realUrl = url
#     if i != 1:
#         realUrl = url2 + "_" + str(i) + ".html"
#     response = requests.get(url=realUrl, headers=headers)
#     response.encoding = "utf-8"
#     soup = BeautifulSoup(response.text, "html.parser")
#     book_list = soup.select(".bookslist li .book-info")
#
#     for book in book_list:
#         bookImg = book.select('.img152 img')[0].get("src")
#         bookTitle = book.select('h3 a')[0].get("title")
#         href = book.select('h3 a')[0].get("href")
#         author = book.select('p')[0].get_text()
#         # 进入详情页面，爬取定价，出版时间，页数信息
#         detailsUrl = domain + href
#         detailResponse = requests.get(url=detailsUrl, headers=headers)
#         detailResponse.encoding = "utf-8"
#         detailSoup = BeautifulSoup(detailResponse.text, "lxml")
#         price = detailSoup.select(".book-details .num")[0].get_text()
#         cbTime = detailSoup.select(".book-details > table tr")[0].select("td")[3].get_text()
#         yeNum = detailSoup.select(".book-details > table tr")[1].select("td")[3].get_text()
#
#         my_book = {
#             "bookImg": bookImg,
#             "bookTitle": bookTitle,
#             "author": author,
#             "price": price,
#             "cbTime": cbTime,
#             "yeNum": yeNum
#         }
#         my_book_list.append(my_book)
# print("耗时:", math.ceil(time.time() - t1), "s")
# print(len(my_book_list))
# # print(my_book_list)
# with open("D:\\my_book_list.json", "w", encoding="utf-8") as fs:
#     json.dump(my_book_list, fs, ensure_ascii=False)


# jd 购物车自动下单功能pc版本
# 京东秒杀脚本，扫码登录版  (有些商品只能通过app购买,此脚本不适用)
# import datetime
# import time
# from selenium.webdriver.common.by import By
# from selenium import webdriver
#
# driver = webdriver.Edge()
#
#
# # 时间格式
# def jdAutoBuy(ordertime):
#     print('.........................START..........................')
#     driver.get("https://passport.jd.com/new/login.aspx")
#     driver.implicitly_wait(5)  # 10秒内扫码登录，过时会跳过
#     time.sleep(10)
#     driver.get("https://cart.jd.com/cart.action")  # 如果没有全选，点击全选
#     if not driver.find_element(by=By.CLASS_NAME, value='jdcheckbox').is_selected():
#         driver.find_element(by=By.CLASS_NAME, value='jdcheckbox').click()
#     driver.save_screenshot('D:\\order.png')
#     while True:
#         now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
#         print(now)
#         if now > ordertime:
#             driver.find_element(by=By.CLASS_NAME, value='common-submit-btn').click()
#             driver.find_element(by=By.ID, value='order-submit').click()
#             time.sleep(30)
#             # 自行去我的订单付款即可
#             print('.........................END..........................')
#
#
# # 调用秒杀函数
# jdAutoBuy('2023-08-28 14:00:00.000000')
